public class Test02 {

    public static void main(String[] args) {

        Integer[] array = {1, 2, 3, 5, 10};
        Double[] array2 = {12.1, 134.2, 198.1};
        String[] array3 = {"anfi","fanfoa","abc"};


        Alg<Integer> alg = new Alg<>();
        Alg<Double> alg2 = new Alg<>();
        Alg<String> alg3 = new Alg<>();

//        System.out.println(alg.Max(array));
//        System.out.println(alg2.Max(array2));
//        System.out.println(alg3.Max(array3));

        System.out.println(Alg2.findMax(array));
    }
}

/**
 * T extends Comparable<T>   这里的extends是扩展的意思
 * 实际上是 T 实现了 Comparable 接口
 * @param <T>
 */
class Alg<T extends Comparable<T>> {

    public T Max(T[] array){
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(array[i].compareTo(max) > 0) {
                max = array[i];
            }
        }
        return max;
    }

}

class Alg2 {

    public static <T extends Comparable<T>> T findMax(T[] array){
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            if(array[i].compareTo(max) > 0){
                max = array[i];
            }
        }
        return max;
    }
}

